<template>
  <div class="receipt-order-edit-wrapper app-container">
    <div class="receipt-order-content">
      <el-form label-width="108px" :model="form" ref="form" :rules="rules">
        <el-row>
          <el-col :span="8">
            <el-form-item label="备案日期" prop="filingDate">
              <el-date-picker clearable
                              v-model="form.filingDate"
                              style="width: 255px"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择备案日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="许可时间" prop="licenseTime">
              <el-date-picker clearable
                              v-model="form.licenseTime"
                              style="width: 255px"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择许可时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="批准文号" prop="approvalNumber">
              <el-input v-model="form.approvalNumber" placeholder="请输入批准文号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="建设单位" prop="buildUnit">
              <el-input v-model="form.buildUnit" placeholder="请输入建设单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工单位" prop="construnctionUnit">
              <el-input v-model="form.construnctionUnit" placeholder="请输入施工单位" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="6">
            <el-form-item label="施工开始路段" prop="expresswayStartSectionId">
              <el-select v-model="form.expresswayStartSectionId" filterable placeholder="请选择施工开始路段" style="width: 100%">
                <el-option
                  v-for="item in expresswaySectionOption"
                  :key="item.expresswaySectionId"
                  :label="item.expresswaySectionName + item.startStation +'至'+ item.endStation"
                  :value="item.expresswaySectionId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工开始方向" prop="constructionStartDirection">
              <el-select v-model="form.constructionStartDirection" placeholder="请选择施工开始方向" style="width: 100px">
                <el-option
                  v-for="dict in dict.type.business_cons_direction_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工开始桩号" prop="constructionStartKm">
              <el-input v-model="form.constructionStartKm" placeholder="开始桩号km">
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">km</i>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工开始桩号" prop="constructionStartM">
              <el-input v-model="form.constructionStartM" placeholder="开始桩号m" >
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">m</i>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="施工结束路段" prop="expresswayEndSectionId" >
              <el-select v-model="form.expresswayEndSectionId" filterable placeholder="请选施工结束路段" style="width: 100%">
                <el-option
                  v-for="item in expresswaySectionOption"
                  :key="item.expresswaySectionId"
                  :label="item.expresswaySectionName + item.startStation +'至'+ item.endStation"
                  :value="item.expresswaySectionId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工结束方向" prop="constructionEndDirection" >
              <el-select v-model="form.constructionEndDirection" placeholder="请选择施工结束方向" style="width: 100px">
                <el-option
                  v-for="dict in dict.type.business_cons_direction_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工结束桩号" prop="constructionEndKm">
              <el-input v-model="form.constructionEndKm" placeholder="结束桩号km" >
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">km</i>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="施工结束桩号" prop="constructionEndM">
              <el-input v-model="form.constructionEndM" placeholder="结束桩号m">
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">m</i>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="施工类型" prop="constructionType">
              <el-select v-model="form.constructionType" placeholder="请选择施工类型" style="width: 255px">
                <el-option
                  v-for="dict in dict.type.business_cons_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="现场负责人" prop="head">
              <el-input v-model="form.head" placeholder="请输入现场负责人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="telePhone">
              <el-input v-model="form.telePhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="计划进场时间" prop="planInTime">
              <el-date-picker clearable
                              v-model="form.planInTime"
                              style="width: 255px"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择计划进场时间"
                              :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工开始时间" prop="construnctionStartTime">
              <el-date-picker clearable
                              v-model="form.construnctionStartTime"
                              style="width: 255px"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择施工开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工完成时间" prop="construnctionEndTime">
              <el-date-picker clearable
                              v-model="form.construnctionEndTime"
                              style="width: 255px"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择施工完成时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="施工组织方案" prop="organizationFile">
              <file-upload  @input="getFileList" :fileLocationName="'organizationFile'" :value="this.organizationFileData"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="24">
            <el-form-item label="施工许可文件" prop="licenseFile">
              <file-upload  @input="getFileList" :fileLocationName="'licenseFile'" :value="this.licenseFileData"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="施工内容" prop="construnctionContent">
              <el-input v-model="form.construnctionContent" type="textarea" placeholder="施工内容"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="其他备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入其他备注" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="所属管辖大队" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属大队" @select="this.getDetpUser"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="deptLeader">
              <el-input v-model="form.deptLeader" placeholder="联系人" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="deptPhone">
              <el-input v-model="form.deptPhone" placeholder="联系电话" :disabled="true"/>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--做个判断 只有新增 和 草稿 状态 才有暂存按钮-->
        <el-button type="primary" @click="submitForm(0)"
                   v-if="this.form.reportStatus == null || this.form.reportStatus == 0">暂 存</el-button>
        <el-button type="danger" @click="submitForm(1)">提 交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import { listreportInfo, getreportInfo, delreportInfo, addreportInfo, updatereportInfo } from "@/api/check/reportInfo";
  import { selectListExpresswaySection } from "@/api/check/expresswaySection";
  import { deptUserTreeSelect } from "@/api/system/user";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import { selectListReportApprLog,addReportApprLog } from "@/api/check/reportApprLog";

export default {
  name: "reportInfoEdit",
  components: { Treeselect },
  dicts: ['business_cons_direction_type', 'business_cons_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报备信息表格数据
      reportInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //  是否显示审核弹出层
      completeOpen: false,
      //  是否显示详情弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportNum: null,
        buildUnit: null,
        construnctionUnit: null,
        approvalNumber: null,
        expresswayStartSectionId: null,
        expresswayEndSectionId: null,
        constructionType: null,
        telePhone: null,
        construnctionStartTime: null,
        construnctionEndTime: null,
        planInTime: null,
        reportStatus: null,
        deptId: null,
        isArchived: null,
      },
      // 表单参数
      form: {},

      // 审核表单参数
      taskForm: {
        reportInfoId: "",// 报备id
        apprStatus: "0",//审批状态
        apprComent: "", // 意见内容
      },

      //  施工组织方案
      organizationFileData:[],
      //  施工许可文件
      licenseFileData:[],
      //  高速路段option
      expresswaySectionOption:[],
      //  组织部门
      deptOptions: undefined,
      //  部门人员
      userOptions: undefined,
      //  审批记录
      reportApprLogList:[],
      // 表单校验
      rules: {
        filingDate: [
          { required: true, message: "备案日期不能为空", trigger: "blur" }
        ],
        buildUnit: [
          { required: true, message: "建设单位不能为空", trigger: "blur" }
        ],
        construnctionUnit: [
          { required: true, message: "施工单位不能为空", trigger: "blur" }
        ],
        licenseTime: [
          { required: true, message: "许可时间不能为空", trigger: "blur" }
        ],
        approvalNumber: [
          { required: true, message: "批准文号不能为空", trigger: "blur" }
        ],
        expresswayStartSectionId: [
          { required: true, message: "施工开始路段id不能为空", trigger: "change" }
        ],
        expresswayEndSectionId: [
          { required: true, message: "施工结束路段id不能为空", trigger: "change" }
        ],
        constructionStartDirection: [
          { required: true, message: "施工开始方向(上行 下行 上下行)不能为空", trigger: "change" }
        ],
        constructionEndDirection: [
          { required: true, message: "施工结束方向(上行 下行 上下行)不能为空", trigger: "change" }
        ],
        constructionStartKm: [
          { required: true, message: "施工开始桩号km不能为空", trigger: "blur" }
        ],
        constructionStartM: [
          { required: true, message: "施工开始桩号m不能为空", trigger: "blur" }
        ],
        constructionEndKm: [
          { required: true, message: "施工结束桩号km不能为空", trigger: "blur" }
        ],
        constructionEndM: [
          { required: true, message: "施工结束桩号m不能为空", trigger: "blur" }
        ],
        constructionType: [
          { required: true, message: "施工类型不能为空", trigger: "change" }
        ],
        head: [
          { required: true, message: "现场负责人不能为空", trigger: "blur" }
        ],
        telePhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        construnctionStartTime: [
          { required: true, message: "施工开始时间不能为空", trigger: "blur" }
        ],
        construnctionEndTime: [
          { required: true, message: "施工完成时间不能为空", trigger: "blur" }
        ],
        planInTime: [
          { required: true, message: "计划进场时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "所属管辖大队不能为空", trigger: "blur" }
        ],
        reviewedBy: [
          { required: true, message: "审核人不能为空", trigger: "blur" }
        ],
      },
      pickerOptions: {
        disabledDate: (time) => {
          let nowData = new Date()
          nowData = new Date(nowData.setDate(nowData.getDate() - 1))
          return time < nowData
        }
      },
    };
  },
  created() {
    this.getExpresswaySectionList();
    this.getDeptTree();
  },
  methods: {
    /** 提交按钮 */
    submitForm(operationType) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          //设置状态
          this.form.reportStatus = operationType;
          if (this.form.reportInfoId != null) {
            updatereportInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addreportInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //获取附件列表
    getFileList(fileLocationName,fileIds,deleteFileId){
      this.form[fileLocationName] = fileIds;

      // if (deleteFileId != undefined) {
      //   this.deleteFileData.push(deleteFileId);
      //   this.form.deleteFileIds = this.deleteFileData.join(",");
      // }
    },
    /** 查询高速路段信息列表 */
    getExpresswaySectionList() {
      this.loading = true;
      selectListExpresswaySection({}).then(response => {
        this.expresswaySectionOption = response.data;
        this.loading = false;
      });
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptUserTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },

    /** 查询部门人员 */
    async getDetpUser (val) {
      //this.reviewedBy = '';
      this.form.deptLeader = val.leader;
      this.form.deptPhone = val.phone;
      this.userOptions = val.deptUsers;
    },

    // 取消按钮
    cancel() {
      this.$tab.closeOpenPage({path: "/settlement/inventorySettlementMonth?settlementType=1"});
    },
  },
};
</script>
<!--<style lang="stylus">-->
<!--.receipt-order-edit-wrapper-->
<!--  .receipt-order-content-->
<!--    width 70%-->
<!--    min-width 900px-->
<!--    margin 0 auto-->
<!--</style>-->
